/**
 * @class Emp.ux.toolbar.Paging
 * @extends Ext.toolbar.Paging
 * @constructor Create a new PagingToolbar with pageSize
 * @param {Object}
 *            config The config object
 * @xtype paging
 */
Ext.define('Emp.ux.toolbar.Paging', {
	extend: 'Ext.toolbar.Paging',
	alias: 'widget.paging',
	
	requires: [
		'Ext.toolbar.TextItem', 
		'Ext.form.field.Number'
	],
	
	getPagingItems: function() {
		var me = this, pagingItems = me.callParent();
		pagingItems.push('-');
		pagingItems.push({
			xtype: 'tbtext',
			text: '每页'
		});
		pagingItems.push({
			xtype: 'numberfield',
			itemId: 'pageSize',
			name: 'pageSize',
			cls: Ext.baseCSSPrefix + 'tbar-page-number',
			allowDecimals: false,
            minValue: 1,
            hideTrigger: true,
            enableKeyEvents: true,
            keyNavEnabled: false,
            selectOnFocus: true,
            submitValue: false,
            // mark it as not a field so the form will not catch it when getting fields
            isFormField: false,
            width: me.inputItemWidth,
            margins: '-1 2 3 2',
			listeners: {
				scope: me,
				specialkey: me.onPageSizeSpecialkey,
				blur: me.onPageSizeBlur
			},
			value: me.store.pageSize
		});
		pagingItems.push({
			xtype: 'tbtext',
			text: '条'
		});
		return pagingItems;
	},

	initComponent: function() {
		this.callParent();
	},

	onPageSizeBlur: function(e) {
		this.child('#pageSize').setValue(this.store.pageSize);
	},

	onPageSizeSpecialkey: function(numberfield, e) {
		if (e.getKey() == e.ENTER) {
			var value = numberfield.getValue();
			if (Ext.isNumber(value)) {
				if (numberfield.isValid()) {
					this.store.pageSize = value;
					this.store.loadPage(1);
				}
			}
		}
	}
});
